
window.onload = function (){
    findAll();
}

/**
 * 查询所有员工
 */
function findAll(){
    axios.get("/em/findAll").then(resp =>{
       var info = resp.data;
       var str = "";
       info.forEach(n =>{
           str += `<tr><td>${n.name}</td><td>${n.phone}</td>
                <td>${n.money}</td><td>${n.status}</td><td>`;

           if(n.status == "在职"){
               str += `<input type="button" value="离职" onclick="dismission(${n.id})"/>
                     <input type="button" value="修改工资" onclick="location.href='/update.html?id=${n.id}'"/>`;
           }
           str += "</td></tr>";

       });
       $("data").innerHTML = str;
    });
}

/**
 * 员工离职
 */
function  dismission(id){
    axios.get("/em/dismission",{
        params:{
            id
        }
    }).then(resp =>{
       if(resp.data == "ok"){
           findAll();
       }
    });
}